package com.huike.web.controller.monitor;

import com.alibaba.excel.EasyExcel;
import com.huike.clues.domain.SysOperLog;
import com.huike.clues.domain.dto.SysOperLogPage;
import com.huike.clues.service.ISysOperLogService;
import com.huike.common.annotation.Log;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.enums.BusinessType;
import com.huike.common.result.Result;
import com.huike.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 操作日志记录
 */
@Slf4j
@Api("日志模块")
@RestController
@RequestMapping("monitor/operlog")
public class SysOperlogController {
    @Resource
    private ISysOperLogService iSysOperLogService;

    /**
     * 日志分页查询
     *
     * @param sysOperLogPage
     * @return
     */
    @GetMapping("list")
    public TableDataInfo<List<SysOperLog>> findPage(SysOperLogPage sysOperLogPage) {

        return iSysOperLogService.findPage(sysOperLogPage);
    }

    /**
     * 操作日志的删除
     *
     * @param ids
     * @return
     */
    @ApiOperation("操作日志删除")
    @DeleteMapping("/{operIds}")
    public Result deleteClen(@PathVariable("operIds") List<Long> ids) {

        return iSysOperLogService.deleteByIds(ids);
    }

    /**
     * 日志清空
     *
     * @return
     */
    @DeleteMapping("/clean")
    public AjaxResult deleteAllClen() {
         iSysOperLogService.deleteAllClen();
         return AjaxResult.success();
    }
//    /**
//     * 操作日志导出接口
//     * @return
//     */
//    @ApiOperation("操作日志导出接口")
//    @GetMapping("/export")
//    public AjaxResult export(@RequestParam(name = "operIds", required = false) List<Long> operIds) {
//        log.info("开始处理操作日志导出接口");
//        AjaxResult ajaxResult = iSysOperLogService.export(operIds);
//        return AjaxResult.success(ajaxResult);
//    }

    /**
     * 日志导出
     * @param response
     * @return
     */
    @GetMapping("export")
    public AjaxResult exportBusinessData(HttpServletResponse response){
       return iSysOperLogService.exportBusinessData(response);
    }
}
